// pages/jiucanhuibao/jiucanhuibao.js
const app = getApp()
var util = require("../../utils/util.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    mealsetyes: [],
    mealsetno: [],
    classid: 0,
    classlist: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    var list = wx.getStorageSync('classlist');
    var classlist = []
    for (var i = 0; i < list.length; i++) {
      var classobj = {
        text: list[i].className,
        value: list[i].classID
      }
      classlist.push(classobj)
    }
    this.setData({
      classid: classlist[0].value,
      classlist:classlist
    })
    this.queryData();
  },

  queryData: function () {

    var that = this;
    var data = {
      "userid": app.globalData.userId,
      "schoolid": app.globalData.schoolId,
      "classid": that.data.classid,
      "appType": app.globalData.appType,
      "appKey": app.globalData.appKey,
      "timeSpan": app.globalData.timespan,
      "mobileSerialnumber": ""
    }
    wx.request({
      url: app.globalData.serverUrl,
      data: {
        "data": JSON.stringify(data),
        'act': "get_mealset"
      },
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded;charset=utf-8'
      },
      success: function (res) {
        console.log(res);

        if (res.data.status == 0) {
          that.setData({
            mealsetno: res.data.data.mealsetno,
            mealsetyes: res.data.data.mealsetyes,
          })
        }
      },
      fail: function (res) {},
      complete: function (res) {
        console.log('submit complete');
      }
    })

  },

  btnclick: function (e) {

    var index = e.currentTarget.dataset.index;
    var mid = this.data.mealsetyes[index].mid;
    var name = this.data.mealsetyes[index].name;

    
    wx.navigateTo({
      url: '../jiucanhuibaokidlist/jiucanhuibaokidlist?mid=' + mid + "&classid=" + this.data.classid+"&name="+name
    })
  },

  onchange({
    detail
  }) {
    this.setData({
      classid: detail
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})